//
//  ByCellOrder.m
//  mijifen_ios
//
//  Created by mc on 2017/10/31.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByCellOrder.h"

@implementation ByCellOrder
{
    UILabel     *_mobileLabel;
    UILabel     *_priceLabel;
    UILabel     *_typeLabel;
    UILabel     *_timeLabel;
    UIView      *_lineView;
    UILabel     *_statusLabel;
    UIButton    *_statusButton;
}
+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByCellOrder";
    ByCellOrder *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        [self createViews];
    }
    return self;
}

- (void)createViews{
    _mobileLabel = [[UILabel alloc] init];
    _mobileLabel.font = FONT(16);
    [self addSubview:_mobileLabel];
    
    _priceLabel = [[UILabel alloc] init];
    _priceLabel.font = FONT(16);
    _priceLabel.textAlignment = NSTextAlignmentRight;
    [self addSubview:_priceLabel];
    
    _statusLabel = [[UILabel alloc] init];
    [self addSubview:_statusLabel];
    _statusLabel.font = FONT(16);
    
    _typeLabel = [[UILabel alloc] init];
    [self addSubview:_typeLabel];
    _typeLabel.backgroundColor = BY_TEXT_COLOR;
    _typeLabel.textColor = [UIColor whiteColor];
    _typeLabel.textAlignment = NSTextAlignmentCenter;

    _timeLabel = [[UILabel alloc] init];
    [self addSubview:_timeLabel];
    _timeLabel.font = FONT(14);
    _timeLabel.textColor = [UIColor darkGrayColor];
    _timeLabel.textAlignment = NSTextAlignmentRight;
    
    _lineView = [[UIView alloc] init];
    [self addSubview:_lineView];
    _lineView.backgroundColor = [UIColor colorWithWhite:0.90 alpha:1];
    
    _statusLabel = [[UILabel alloc] init];
    [self addSubview:_statusLabel];
    _statusLabel.font = FONT(16);
    
    _statusButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:_statusButton];
    _statusButton.layer.cornerRadius = 30 / 2;
    _statusButton.layer.borderWidth = 1;
    
}

- (void)setModel:(ByModelOrder *)model{
    _model = model;
    
    [_mobileLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(10);
        make.top.equalTo(self.mas_top).offset(10);
        make.size.mas_equalTo(CGSizeMake((SCREEN_WIDTH - 20) / 2, 30));
    }];
    _mobileLabel.text = _model.mobile;
    
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_mobileLabel.mas_right);
        make.right.equalTo(self.mas_right).offset(-10);
        make.top.equalTo(_mobileLabel.mas_top);
        make.size.mas_equalTo(CGSizeMake((SCREEN_WIDTH - 20) / 2, 30));
    }];
    _priceLabel.text = [NSString stringWithFormat:@"¥%@",_model.price];

    CGFloat width = [@"线下移动支付" getSizeOfString:16].width + 30;
    [_typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_mobileLabel.mas_bottom).offset(10);
        make.left.equalTo(_mobileLabel.mas_left);
        make.size.mas_equalTo(CGSizeMake(width, 30));
    }];
    _typeLabel.text = _model.type;

    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-10);
        make.top.equalTo(_priceLabel.mas_bottom).offset(15);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 20 - width, 20));
    }];
    _timeLabel.text = _model.create_time;

    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_typeLabel.mas_bottom);
        make.left.equalTo(self.mas_left).offset(10);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 20, 1));
    }];

    width = [@"验码" getSizeOfString:16].width + 60;
    [_statusButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_lineView.mas_bottom).offset(10);
        make.right.equalTo(self.mas_right).offset(-10);
        make.size.mas_equalTo(CGSizeMake(width, 30));
    }];


    [_statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_lineView.mas_bottom).offset(10);
        make.left.equalTo(_mobileLabel.mas_left);
        make.right.equalTo(_statusButton.mas_left).offset(- 10);
        make.bottom.equalTo(self.mas_bottom).offset(-10);
    }];
    switch (_model.status.integerValue) {
        case 0: // 退款
        {
            [_statusButton setTitle:@"退款" forState:UIControlStateNormal];
            [_statusButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
            _statusButton.layer.borderColor = [UIColor redColor].CGColor;
            _statusLabel.text = @"状态：完成";
        }
            break;
        case 1: // 配送
        {
            [_statusButton setTitle:@"配送" forState:UIControlStateNormal];
            [_statusButton setTitleColor:BY_TEXT_COLOR forState:UIControlStateNormal];
            _statusButton.layer.borderColor = BY_TEXT_COLOR.CGColor;
            _statusLabel.text = @"状态：未完成";
        }
            break;
        case 2: // 验码
        {
            [_statusButton setTitle:@"验码" forState:UIControlStateNormal];
            [_statusButton setTitleColor:[UIColor colorWithR:60 g:158 b:218] forState:UIControlStateNormal];
            _statusButton.layer.borderColor = [UIColor colorWithR:60 g:158 b:218].CGColor;
            _statusLabel.text = @"状态：未自取";
        }
            break;

        default:
            break;
    }

}



@end
